 <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Expires" CONTENT="0">
        <meta http-equiv="Cache-Control" CONTENT="no-cache">
        <meta http-equiv="Pragma" CONTENT="no-cache">
        <meta content="telephone=no" name="format-detection" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
        <title>选择开票企业</title>
        <link type="text/css" rel="stylesheet" href="../../wx/resource/fapiao.css">
        <link rel="stylesheet" href="../../resource/weui.min.css"/>
        <link rel="stylesheet" href="../../resource/example.css"/>
        <script type="text/javascript" src="../../resource/jweixin-1_002.js"></script>
        <script type="text/javascript" src="../../resource/jweixin-1.js"></script>
        <script src="../../resource/jquery-1.js"></script>
        <script src="../../resource/qrcode.js"></script>
        <script src="../../resource/jquery-barcode.js"></script>
        <script src="../../script/api.js"></script>
    </head>
    

    <body>
    <div id="loadingToast" style="display:none;z-index:1000;">
        <div class="weui-mask_transparent"></div>
        <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">数据加载中...</p>
        </div>
	</div>
	<div  class="js_dialog" id="iosDialog1" style="display: none;-webkit-transform:0;transform:0;left:10%">
            <div class="weui-mask"></div>
            <div class="weui-dialog">
                <div class="weui-dialog__hd" id="dialog_title"></div>
                <div class="weui-dialog__bd" id="dialog_message"></div>
                <div class="weui-dialog__ft">
                    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default" onclick="cancelInv()">取消</a>
                    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" onclick="fillInv()">确定开票</a>
                </div>
            </div>
        </div>
    <div class="page__bd">
    	<div class="weui-panel weui-panel_access">
    		<div class="weui-panel__hd" style="background-color:#efeff4">请选择开票企业</div>
    		<div class="weui-panel__bd">
    			<div id="Qy_div">
<!-- 	    			<a class='weui-media-box weui-media-box_appmsg' href='javascript:void(0);'> -->
<!-- 	    				<div class='weui-media-box__bd'> -->
<!--     						<h4 class='weui-media-box__title'>企业名称</h4> -->
<!--     						<p class='weui-media-box__desc'>测试企业123456</p> -->
<!--     					</div> -->
<!--     				</a> -->
    			</div>
    			<div class="weui-panel__ft">
    				<a class="weui-cell weui-cell_access weui-cell_link" onclick="AddQy()">
    					<div class="weui-cell__bd">新增企业信息</div>
    					<span class="weui-cell__ft"></span>
    				</a>
    			</div>
    		</div>
    	</div>
    </div>
    </body>
    <script>
    //var openid = 'oOQHZv1_mw8ISVErxjJUk847Gja4';
    var openid = $api.getStorage('openid');;
    var xlist;
    var list_index;
    var orderid;
    var kpmethod;
    
//  window.onload = function(){
//  	getP();
//  }
//  
//  function getP(){
//  	apiready = function(){
//  		orderid = api.pageParam.orderid;
//  		kpmethod = api.pageParam.kpmethod;
//  		//api.alert({ msg: JSON.stringify(orderid)});
//  		console.info(orderid);
// 		 }
//  }
		
    
	function gridUserInfo(){
		//$("#loadingToast").fadeIn(100);
		apiready = function(){
			api.addEventListener({
    			name: 'reload'
			}, function(ret, err) {
   			 	window.location.reload();
			});
		orderid = api.pageParam.orderid;
  		kpmethod = api.pageParam.kpmethod;
		api.ajax({
    		url: 'http://wechat.scjinsui.com/weixin/wxUser/gridUserInfo2.do?openId='+openid,
    		method: 'post',
    		data: {
//  		    values: {
// 		         opneId: 'oOQHZv1_mw8ISVErxjJUk847Gja4'
// 		     }
   		 }
		}, function(ret, err) {
			//api.alert({ msg: JSON.stringify(ret) });
		if(ret){
   		 xlist=ret.xlist;
	        	if(ret.flag != null){
	        		var len = xlist.length - 1;
	        		if(xlist[len].USERNAME !="" && typeof(xlist[len].USERNAME) != 'undefined'){
			        	var taxcode=xlist[len].TAXCODE==undefined?"&nbsp;":xlist[len].TAXCODE;
						if(xlist[len].TAXCODE!==undefined &&
								xlist[len].ADDRESS!==undefined &&
								xlist[len].BANK_NAME!==undefined &&
								xlist[len].BANK_NUMBER!==undefined &&
								xlist[len].PHONE_NUMBER!==undefined){
							disc="该信息支持开具增值税专用发票";
						}
						var s="<a class='weui-media-box weui-media-box_appmsg' href='javascript:void(0);' onclick='chooseQy(" + len + ")'>"+
						"<div class='weui-media-box__bd'>"+
						"<h4 class='weui-media-box__title'>" + xlist[len].USERNAME + "</h4>"+
						"<p class='weui-media-box__desc'>" + taxcode + "</p></div></a>";
						$("#Qy_div").append(s);
	        		}
	        	}
	        	
	        	for(var i=0;i<xlist.length;i++){
	        		var taxcode=xlist[i].TAXCODE==undefined?"无税号":xlist[i].TAXCODE;
					if(xlist[i].USERNAME!==undefined && xlist[i].USERNAME!= ""){
					var s="<a class='weui-media-box weui-media-box_appmsg' href='javascript:void(0);' onclick='chooseQy(" + i + ")'>"+
    						"<div class='weui-media-box__bd'>"+
    						"<h4 class='weui-media-box__title'>" + xlist[i].USERNAME + "</h4>"+
							"<p class='weui-media-box__desc'>" + taxcode + "</p></div></a>";
						$("#Qy_div").append(s);
					}
	        	}
	        	}else{
	        		api.alert({msg:'网络异常'});
	        	}
		});
}
	}
	
	
	function AddQy(){
		//window.location.href='./Invoice_add.jsp?openid='+openid;
		api.openWin({
	        name: '新增开票企业',
	        //url: './Invoice_add.html',
	        url:'../yst/tjxx.html',
	        pageParam:{
	        	openid : openid
	        }
        });
	}
	
	function chooseQy(i){
		var taxcode=xlist[i].TAXCODE==undefined?"无税号":xlist[i].TAXCODE;
		$("#dialog_title").html("是否开具当前企业发票");
		$("#dialog_message").html("<p>"+xlist[i].USERNAME+"</p><p>"+taxcode+"</p>");
		$("#iosDialog1").fadeIn(100);
		list_index=i;
	}
	
	function cancelInv(i){
		$("#iosDialog1").fadeOut(100);
	}
	
	function fillInv(){
		$("#iosDialog1").hide();
		$("#loadingToast").show();
		if(orderid == null || orderid==""){
			//api.alert({msg:('暂未获取到订单号,请稍候重试')});
			api.ajax({
    			//url: 'http://192.168.76.50:8181/fpkj/postKp0.do',
    			url: 'http://wechat.scjinsui.com/weixin/fpkj/postKp0.do',
    			method: 'post',
    			data: {
     			   values: {
      			   	invoicemerid : api.pageParam.invoiceMerId.replace(/\+/g, '%2B'),
	        	   	terminalid : api.pageParam.terminalId.replace(/\+/g, '%2B'),
	        	   	qr:xlist[list_index].QR,
	        	   	amount:api.pageParam.je,
	        	   	merchant:api.pageParam.merid,
	        	   	openid:api.pageParam.openid,
	        	   	produce:api.pageParam.produce, 
	        	  	 bz:api.pageParam.bz,
	        	  	 shmc:api.pageParam.qymc,
	        	  	 ggxh:api.pageParam.ggxh,
	        	   	jldw:api.pageParam.jldw,
	        		slv:api.pageParam.slv,
	        		key:api.pageParam.key,
	        		scaned :api.pageParam.scaned,
	        		fno : api.pageParam.fno
      			  }
    			}
			}, function(ret, err) {
   			 if (ret) {
   			 	 if(ret.msg=="OK"){
	           			//window.location.href="<%=basePath %>wx/Pay_success.jsp?msgType=2";
	           			api.openWin({
	                           name: 'success',
	                           url: './Pay_success.html',
	                               pageParam:{
	                               		msgType : '2'
	                               }
                           });
		           	}else{
		           		api.openWin({
	                           name: 'failed',
	                           url: './Pay_failed.html',
	                               pageParam:{
	                               		msgType : '2'
	                               }
                           });
		           	}
	        	   $("#loadingToast").hide();
   			 } else {
   			     console.log('服务请求错误,请联系管理员...');
   			     api.alert({msg:'网络异常'});
   			 }
			});
			
		}else if(orderid != null && !orderid==""){ 
				//api.alert({msg:('http://wechat.scjinsui.com/weixin/wxKpxx/'+kpmethod+'.do---'+orderid+"---"+xlist[list_index].QR+"---"+xlist[list_index].YW)});
				
				//api.alert({msg:('http://wechat.scjinsui.com/weixin/wxKpxx/'+kpmethod+'.do')});
				api.ajax({
  					 url: 'http://wechat.scjinsui.com/weixin/wxKpxx/'+kpmethod+'.do',
   					 method: 'post',
   					 data: {
    					    values: {
    					        orderid : orderid,
    					        qr:xlist[list_index].QR,
	        	   				yw : xlist[list_index].YW
     					   }
   					 }
					}, function(ret, err) {
   					 if (ret) {
   					 	//api.alert({msg:('1')});
   					 	//api.alert({msg:(ret.success)});
  					     if(ret.success){
	           				//window.location.href="<%=basePath %>wx/Pay_success.jsp?msgType=2";
	           				//api.alert({msg:('跳转成功页面')});
	           				api.openWin({
	                               name: '支付成功',
	                               url: './Pay_success.html',
	                               pageParam:{
	                               		msgType : '2'
	                               }
                               });
		           		}else{
		           			console.log({msg:(ret.rst)});
		           			//window.location.href="<%=basePath %>wx/Pay_failed.jsp?msgType=2";
		           			//api.alert({msg:(ret.rst)});
		           			//api.alert({msg:('跳转失败页面')});
		           			api.openWin({
	                               name: '支付失败',
	                               url: './Pay_failed.html',
	                               pageParam:{
	                               		msgType : '2'
	                               }
	                               
                               });
		           		}
	        	   		$("#loadingToast").hide();
   					 } else {
   					 	api.alert({msg:('服务请求错误异常！')});
   					 	api.alert({msg:'网络异常'});
   					 }
					});
		}
		
	}
	
	var ua = navigator.userAgent.toLowerCase();
	var isWeixin = ua.indexOf('micromessenger') != -1;
	var isAndroid = ua.indexOf('android') != -1;
	var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);


	if (!isWeixin) {
		//openid="123456";
		gridUserInfo();
		
	}else{//微信客户端
		//config 注入成功后异步回调wx.ready方法
		
		
	}
	
	
	
    </script>
</html>